<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@include file="../../v2/common/jspcommon.jsp"%>
<script type="text/javascript" src="../../../js/jquery_pager/jquery.pager.js"></script>
<title>添加、修改新产品</title>
<script type="text/javascript">
	$(function(){
		$("#pager").pager({ pagenumber: ${pageModelProduct.currentPage}, 
			pagecount: ${pageModelProduct.totalPage},
			buttonClickCallback: function(page){
				$("#product_content").load("/misc/product/readProduct.htm?page="+page);
			}
		});
	});
	
	/* 删除商品 */
	function deleteProduct(productId){
		if(p_del()){
			$.post("/misc/product/deleteProduct.htm",{
				identifier:productId
			},function(data){
				if(data=='success'){
					alert("删除成功");
					clearRushStyle();
					$("#product_content").load("/misc/product/readProduct.htm?page=${page}");
				}
			});	
			}else{
				    $("#product_content").load("/misc/product/readProduct.htm?page=${page}");
			}
	}
	
	function p_del() {
		   var msg = "您真的确定要删除吗？删除后将不可恢复！！\n\n请确认！";
		   if (confirm(msg)==true){
		    return true;
		   }else{
		    return false;
		   }
	  }
	//更新商品
	function updateProduct(productId){
		$('#product_content').load("/misc/product/updateProduct.htm?productId="+productId);
	}
	//今日推荐
	function recommend(productId){
		$.post("product/recommendProduct.htm",{
			productId:productId
		},function(data){
			if(data=='success'){
				alert("推荐成功");
				clearRushStyle();
				$("#product_content").load("/misc/product/readProduct.htm?page=${page}");
			}
		});	
	}
	//上架
	function openProduct(productId){
		$.post("/misc/product/openProduct.htm",{
			productId:productId
		},function(data){
			if(data=='success'){
				alert("上架成功");
				$("#product_content").load("/misc/product/readProduct.htm?page=${page}");
			}
		});	
	}
	
	//下架
	function closedProduct(productId){
		$.post("product/closedProduct.htm",{
			productId:productId
		},function(data){
			if(data=='success'){
				alert("下架成功");
				$("#product_content").load("/misc/product/readProduct.htm?page=${page}");
			}
		});	
	}
	
</script>
</head>
<body>
	<table border="1" width="70%">
			<tr >
				<td colspan="6" style="text-align: center;color: black;">所有的产品如下：</td>
			</tr>
			<tr> 
				<td>产品标题</td>
				<td>产品价格</td>
				<td>产品数量</td>
				<td>产品封面</td>
				<td>产品简介</td>
				<td>产品分类名称</td>
				<td>操作</td>
				<td>特殊操作</td>
				<td>上/下架产品</td>
			</tr>
			
			<c:forEach items="${pageModelProduct.list}" var="productList">
			<tr> 
				<td>${productList.title}</td>
				<td>${productList.price}</td>
				<td>${productList.amount}</td>
				<td>
					<img alt="" src="${productList.imageServer}${productList.cover}" width="60px;">
				</td>
				<td>${productList.description}</td>
				<td>${productList.categoryName}
				<c:if test="${productList.isClosed}">
				     <p style="color: red;">*今日推荐*</p>
				</c:if>
				</td>
				
				<td>
					<div><input type="button" value="编辑" onclick="updateProduct('${productList.identifier}')" style="width: 100px"></div>
					<%-- <div><input type="button" value="删除" onclick="deleteProduct('${productList.identifier}')" style="width: 100px;color: red;"></div> --%>
				</td>
				<td>
					<c:if test="${productList.category =='01'}">
					<a	href="javascript:void(0);" onclick="recommend('${productList.identifier}');" style="font-size: 15px">今日推荐</a>
					</c:if>
				</td>
				<td>
					<c:if test="${productList.enabled}">
						<a	href="javascript:void(0);" onclick="closedProduct('${productList.identifier}')" style="font-size: 15px">产品下架</a>
					</c:if>
					<c:if test="${productList.enabled==false}">
						<a	href="javascript:void(0);" onclick="openProduct('${productList.identifier}')" style="font-size: 15px;color: #FF1493;">产品上架</a>
					</c:if>
					
				</td>
			</tr>
			</c:forEach>
		</table>
		
			<c:if test="${pageModelProduct.totalRecord > 0}">
				<div id="pager" class="h_page"></div>
			</c:if>
		
		
</body>
</html>